<?php
	use app\assets\AppAsset;
	use yii\helpers\Url;
	use yii\helpers\Html;
	use yii\web\Authentication;

	AppAsset::register($this);
	if (!Authentication::isLoggedIn()) {
		\Yii::$app->getResponse()->redirect(['site/login']);
	}
	
	$this->registerJsFile('assets/nicEdit/nicEdit.js', ['position' => \yii\web\View::POS_BEGIN]);

?>
<div style="padding:0 10px;">
	<textarea id="area1" style="width:100%;height:500px;"></textarea>
</div>

<form name="waannoucement" method="post" action="<?=Url::to(['waannouncement/save'])?>" onsubmit="form1_onsubmit();">
<input type="hidden" name="inputcontents" id="inputcontents" />
<div style="margin:auto; padding:20px; text-align:center;">
<?php
 	echo Html::submitButton('<span class="glyphicon glyphicon-floppy-disk"></span> Save',
 							 ['class' => 'btn btn-success btn-lg', 'name' => 'submit-button']);
?>
</div>
</form>

<script type="text/javascript">
	new nicEditor().panelInstance('area1');

	nicEditors.findEditor('area1').setContent('<?php 
			$fname="../views/site/annoucement.php";
			$myfile = fopen($fname, "r") or die("Unable to open file!");
			if (filesize($fname)) {
				echo str_replace("'", "\'", fread($myfile,filesize($fname)));
			} else {
				echo '';
			}
			
			fclose($myfile);
		?>');

	function form1_onsubmit(){
		jQuery('#inputcontents').val(nicEditors.findEditor('area1').getContent());
		return true;
	}
</script>